package tv.geir.slackspace.code;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Holds a class' name and definition (bytecode).
 * 
 * @author Geir Gullestad Pettersen
 *
 */
public class ClassDefinition implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/* name of the class this */
	private String className;
	
	/* class definition */
	private byte[] definition;
	
	/**
	 * Constructor, creates a <code>ClassDefinition</code>
	 * 
	 * @param className
	 * @param definition
	 */
	public ClassDefinition(String className, byte[] definition) {
		setClassName(className);
		setDefinition(definition);
	}
	
	
	/**
	 * @return
	 */
	public String getClassName() {
		return className;
	}
	/**
	 * @param className
	 */
	public void setClassName(String className) {
		this.className = className;
	}
	/**
	 * @return
	 */
	public byte[] getDefinition() {
		return definition;
	}
	/**
	 * @param definition
	 */
	public void setDefinition(byte[] definition) {
		this.definition = definition;
	}
	
	@Override
	public int hashCode() {
		return className.hashCode();
	}
	
	public boolean equals( Object other ) {
		if( !( other instanceof ClassDefinition )) {
			return false;
		}
		ClassDefinition rhs = (ClassDefinition) other;
		if( this.getClassName().equals( rhs.getClassName() ) &&
	        this.getClass().equals( rhs.getClass() ))
		{
			return true;
		} 
		else 
		{
			return false;
		}
	}
	
	@Override
	public String toString() {
		ToStringBuilder s = new ToStringBuilder(this);
		s.append("className", className);
		if( definition == null || definition.length <=0 ) {
			s.append("definition", "MISSING" );
		}
		return s.toString();
	}
}
